package com.kws.merchant.mapper;

import com.kws.merchant.domain.OperationTicket;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kws.system.api.domain.SysUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * 运维-两票管理(OperationTicket)表数据库访问层
 *
 * @author yxy
 * @since 2024-10-28 08:54:05
 */

public interface OperationTicketMapper extends BaseMapper<OperationTicket> {


    @Select("select count(*) from tb_operation_ticket o  where ${sql};")
//    @Select("select count(*) from tb_operation_ticket o left join tb_operation_ticket_item ti on o.id=ti.ticket_id LEFT JOIN tb_item t on ti.item_id=t.id where ${sql};")
    int countToTal(@Param("sql") String sql);

    @Select("select o.*,u.nick_name as workPrincipalName  from tb_operation_ticket o left join sys_user u on o.work_principal=u.user_id  where ${sql} limit ${sizeNum},${totalPage};")
    List<OperationTicket> getRecords(@Param("sql") String sql,@Param("sizeNum") int sizeNum,@Param("totalPage") Integer totalPage);

    @Select("select * from sys_user where nick_name='${workPrincipal}' and company_id=${companyId}")
    SysUser detailByNickName(@Param("workPrincipal") String workPrincipal,@Param("companyId") Long companyId);

    @Select("Select o.*,u.nick_name as workPrincipalName,u1.nick_name as handleGuardianName,u2.nick_name as handleOperatorName from tb_operation_ticket o left join sys_user u on o.work_principal=u.user_id left join sys_user u1 on o.handle_guardian=u1.user_id join sys_user u2 on o.handle_operator=u2.user_id where o.id=${id}")
    OperationTicket detailById(@Param(("id")) Long id);
}
